//
//  PopoverPresentaionController.swift
//  weibo_swift
//
//  Created by dulinlong on 15/7/1.
//  Copyright © 2015年 sheji_56. All rights reserved.
//

import UIKit

class PopoverPresentaionController: UIPresentationController {

    var presentFrame = CGRectZero
    
    //关闭控制器
   func closes(){
        presentedViewController.dismissViewControllerAnimated(true, completion: nil)
    }
    
    //容器视图将要呈现
    override func containerViewWillLayoutSubviews(){
        super.containerViewWillLayoutSubviews()

        dummyView.frame = containerView!.bounds
        containerView?.insertSubview(dummyView, atIndex: 0)
        
        presentedView()?.frame = presentFrame
    }
    
    /// 遮罩视图
    lazy var dummyView: UIView = {
        let v = UIView()
        v.backgroundColor = UIColor(white: 0, alpha: 0.3)
        
        //添加手势
        let tap =  UITapGestureRecognizer(target: self, action: "closes")
        v.addGestureRecognizer(tap)
        
        return v
    }()
    
}
